/**
 * 给定一个字符串caption，内含用空格分隔的多个单词
 * 要求将这些单词按照驼峰规则连接成一个单词。
 * 驼峰规则：首单词全小写，其后单词首字母大写、其余全小写
 */
class Solution {
public:
    string generateTag(string caption) {
        vector<string> vec;
        int n = caption.length();
        int k = 0;
        while(1){
            while(k < n and ' ' == caption[k]) ++k;
            if(k == n) break;

            int o = 0;
            while(k + o < n and isalpha(caption[k + o])) ++o;
            vec.emplace_back(caption.substr(k, o));
            if((k += o) == n) break;
        }

        for(auto & s : vec){
            for(auto & c : s){
                c = this->chkToLower(c);
            }
        }

        if(vec.empty()) return "#";
        
        string ans = string(1, '#') + vec[0];
        ans[1] = this->chkToLower(ans[1]);
        for(auto it=++vec.begin(),et=vec.end();it!=et;++it){
            (*it)[0] = this->chkToUpper((*it)[0]);
            ans += *it;
            if(ans.length() >= 100) break;
        }
        return ans.substr(0, 100);
    }

    char chkToLower(char c){
        if(isupper(c)) return tolower(c);
        return c;
    }

    char chkToUpper(char c){
        if(islower(c)) return toupper(c);
        return c;
    }
};